#ifndef __UDTClientSession__
#define __UDTClientSession__

#include <udt.h>
#include <Poco/AutoPtr.h>
#include <list>
#include <QObject>
#include <QTimer>
//#include <poco/Util/AbstractConfiguration.h>

class CUdtClientSession
        :public QObject
{
    Q_OBJECT
public:
	CUdtClientSession(void);
	CUdtClientSession(UDTSOCKET aSocket,const std::string& aPathFile);
public:
	virtual ~CUdtClientSession(void);
public:
        void SetSocket(UDTSOCKET aSocket) {iSocket = aSocket; }
	bool SenderWaitingRequest();
	void SendFile(); // send file ( not generate file XML because a file size is too small
	void SendFileDescription();
	void SendPiece(const int& aOrder);
	void SendAll();

	void RecvFile();// receive full file
	std::list<int> receiveAllPiece();
	bool RecvPiece(const int& aPiece);
	bool getFileDescription();

	std::list<int> CheckRecvSuccessful();
	void TryRecvAgain();
public:
	void setNameSession(const std::string& aName){iNameSession = aName;};
signals:
        void PieceSent(const int& aPieceIndex);
        void PieceReceived(const int& aPieceIndex);
        void SentFileDescriptions(bool);
        void ReceivedFileDescriptions(bool);
        void SendingFileDescription();
        void TotalFileSizeInfo(Poco::UInt64);
        void TotalPiecesCount(int);
        void BadFileDescription();
		void finished();

private:

	UDTSOCKET iSocket;
	std::string iNameSession;
	std::string iPathFile ;
	std::list<std::string> iListMD5;
	std::list<std::string>			iListSizePiece;
    int iPieceSize;
	QTimer* iTimer;
	bool iStop;
private:
	//Poco::AutoPtr<Poco::Util::AbstractConfiguration> iConfiguration;
};

#endif
